var http = require('http');
var querystring = require('querystring');
var formData = querystring.stringify({
    "content": "深入浅出，非常好！！！！！",
    'cid': 348,
    'mid': 8837
});
var optins = {
    hostname: 'www.imooc.com',
    port: 80,
    path: '/course/docomment',
    method: 'POST',
    headers: {
        "Accept": "application / json, text / javascript, */*; q=0.01",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
        "Connection": "keep-alive",
        "Content-Length": formData.length,
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        "Cookie": "imooc_uuid=b1014f0b-ac87-4293-a821-ab5992d35605; imooc_isnew_ct=1530608583; IMCDNS=0; loginstate=1; apsid=MyOTQ2YWNjZmMxZTI3YTJlYzQ5M2ZmZTA0YzRhNWMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMTAzODYwNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyNzg0Mjc0NDRAcXEuY29tAAAAAAAAAAAAAAAAAAAAADViYWE2NzU1NzI4NDE2Mjg3NWZhMGIwOGM5ZmRhNzg57zs7W%2B87O1s%3DNj; last_login_username=278427444%40qq.com; PHPSESSID=qf9uqk3uq0mb3f5lmpe6d26nc7; imooc_isnew=2; Hm_lvt_fb538fdd5bd62072b6a984ddbc658a16=1530608584,1530685017,1530752989; Hm_lpvt_fb538fdd5bd62072b6a984ddbc658a16=1530752989; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1530608584,1530685018,1530752989; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1530784214; cvde=5b3d6fdd4f155-28",
        "DNT": "1",
        "Host": "www.imooc.com",
        "Origin": "https://www.imooc.com",
        "Referer": "https://www.imooc.com/video/8837",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36",
        "X-Requested-With": "XMLHttpRequest"
    }
};

var req = http.request(optins, function (res) {
    res.on('data', function (chunk) {
        console.log(Buffer.isBuffer(chunk))
    });

    res.on('end', function () {
        console.log('评论完毕！')
    });

});
req.on('error', function (e) {
    console.log('评论出错：' + e.message);
})
req.write(formData);
req.end();